var app = getApp();
var appData = app.globalData;
Page({
  data: {
    list: [],
    searchContent: "",
    types: 0,
    page: 0,
    isSearch: false,
    canMove: 1,
    hid:false,
    value:''
  },
  // 清空历史记录
  removeRecordTap: function () {
    console.log(".....");
    this.setData({
      list: []
    })
    appData.searchUserData = [];
    wx.removeStorageSync("searchUserData");
    wx.setStorageSync("searchUserData", appData.searchUserData);
  },
  onLoad: function (options) {
    appData.searchUserData = wx.getStorageSync("searchUserData");
    if (!appData.searchUserData) {
      appData.searchUserData = [];
    }
  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    this.setData({
      isSearch: false
    })
    console.log(appData.searchUserData);
    if (appData.searchUserData.length > 0) {
      this.setData({
        list: appData.searchUserData
      });
    }
    console.log(appData.searchUserData);
  },
  onHide: function () {

  },
  onUnload: function () {
    // 页面关闭
    this.setData({
      list: []
    });
  },
  toFocus:function(e){
    if (e.detail.value != '') {
      this.setData({
        hid: true,
      })
    }
  },
  toInput:function(e){
    console.log(e)
    if (e.detail.value != '') {
      this.setData({
        hid: true,
      })
    } else {
      this.setData({
        hid: false,
      })
    }
  },
  toBlur: function () {
    this.setData({
      hid: false
    })
  },
  goToHome:function(){
    wx.navigateBack()
  },
  qkwenzi:function(){
    this.setData({
      value:''
    })
  },
  forSubmit:function(e){
    console.log(e.detail.value)
    if (appData.searchUserData.indexOf(e.detail.value) < 0 && e.detail.value || appData.searchUserData.indexOf(e.detail.value) > 9 && e.detail.value){
        appData.searchUserData.unshift(e.detail.value);
        wx.setStorageSync("searchUserData", appData.searchUserData);
        // this.setData({
        //   list: appData.searchUserData
        // });
    }
    wx.navigateTo({
      url: '/pages/others/searchResult/searchResult?condition=' + e.detail.value,
    })
  },
  navToBussess:function(e){
    console.log(e)
    var condition = e.currentTarget.dataset.info;
    wx.navigateTo({
      url: '/pages/others/searchResult/searchResult?condition=' + condition,
    })
  }
})
